package svc.elib.linkpred;

import java.util.Collection;
import java.util.Iterator;

import svc.elib.db.Author;
import svc.elib.socnet.Net;

public class CommonNeighbours implements LPMetric {

	@Override
	public double score(Author a, Author b, Net n) {
		int numCommons = 0;
		Collection<Author> bNeis = n.getGraph().getNeighbors(b);
		Iterator<Author> anit = n.getGraph().getNeighbors(a).iterator();
		while (anit.hasNext()) {
			Author anei = anit.next();
			if (bNeis.contains(anei)) 
				++numCommons;
		}
		
		return numCommons;
	}

}
